//
//  IncomeViewController.m
//  Cat
//
//  Created by lushitong on 2018/12/5.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "IncomeViewController.h"
#import "IncomeTableView.h"
#import "DetailsViewController.h"
#import "HttpUserManager.h"
#import "BindViewController.h"
#import "GetCrashViewController.h"
#import "BindViewController.h"
#import "YuErViewController.h"

@interface IncomeViewController ()

@property (nonatomic, strong) UIButton *bottomButton;
@property (nonatomic, strong) IncomeTableView *tableView;
@end

@implementation IncomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadAllSubViews];
	[self.topTitleView setDetailDic:@{Nav_Title:@"收益",Nav_RightTxt:@"明细"}.mutableCopy];
	[self.view bringSubviewToFront:self.topTitleView];
}

- (void)loadAllSubViews {
	[self.view addSubviews:@[self.tableView,self.bottomButton]];
	
	[self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.and.right.and.bottom.equalTo(self.view);
		make.height.equalTo(@(kQKFitModuleDecimal(50)));
	}];
	
	[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.and.right.equalTo(self.view);
		make.top.equalTo(self.topTitleView.mas_bottom);
		make.bottom.equalTo(self.bottomButton.mas_top);
	}];
}

- (void)getCrash {
	[HttpUserManager balanceGetSuccess:^(NSString * _Nonnull alipayNO, NSString * _Nonnull realName, NSNumber * _Nonnull amount) {
		if (realName.length == 0) {
			BindViewController *VC =[[BindViewController alloc] init];
			[self.navigationController pushViewController:VC animated:YES];
		} else {
			GetCrashViewController *cash = [[GetCrashViewController alloc] init];
			cash.alipayaccount = alipayNO;
			cash.alipayName = realName;
			cash.balanceNumber = amount.stringValue;
			[self.navigationController pushViewController:cash animated:YES];
		}
	} failure:^(NSInteger code, NSString *message) {
		[FLProgressHUD showError:message];
	}];
}

- (void)p_topRightBtnClick {
	YuErViewController *details = [[YuErViewController alloc] init];
	[self.navigationController pushViewController:details animated:YES];
}

#pragma mark----- lazy init -----

- (UIButton *)bottomButton {
	if (!_bottomButton) {
		_bottomButton = [UIButton buttonWithTitle:@"立即提现" color:COLOR_WITH_HEX(0x57524F) font:[UIFont boldSystemFontOfSize:kQKFitFont(16)]];
		[_bottomButton setBackgroundImage:[UIImage imageWithColor:COLOR_WITH_HEX(0xFFC236)] forState:UIControlStateNormal];
		[_bottomButton addTarget:self action:@selector(getCrash) forControlEvents:UIControlEventTouchUpInside];
	}
	return _bottomButton;
}

- (IncomeTableView *)tableView {
	if (!_tableView) {
		_tableView = [[IncomeTableView alloc] initWithFrame:CGRectMake(0.0, self.topTitleView.bottom, self.view.width, self.view.bottom - kQKFitModuleDecimal(50)) sections:2];
	}
	return _tableView;
}
@end
